﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CardLib;
namespace Durak_Game
{
    public partial class Form1 : Form
    {
        private Random random =new Random();
        private Durak durakGame;
       /* private List<CardBox> computerCards;
        private List<CardBox> myCards;*/
        private CardBox topCard;
       
        public Form1()
        {
            InitializeComponent();
        }

        private void cardBox1_Load(object sender, EventArgs e)
        {
            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            initGame();
            Cursor.Current = Cursors.Default;
           
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
          

        }

        private void newGameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            initGame();
            Cursor.Current = Cursors.Default;
        }

        private void initGame()
        {
            mainPanel.Visible = true;
            startGameButton.Visible = true;
            durakGame = new Durak();
            durakGame.clearLogFile();
            durakGame.log("Game Started");
            initComputerCardBox();
            initMyCardBox();
            initTopCard();
            label5.AutoSize = true;
            durakGame.setLabels(label4, label3, label5,label7,label8);
            durakGame.setPanels(tablePanel,computerDesk,myPanel);
            durakGame.setComputerCards();
            durakGame.setMyCards();
            durakGame.setTopCard(topCard);
            durakGame.setUI(this);

           
            

        }

        private void handleClick1(object sender, EventArgs e)
        {
            durakGame.playGame(1);
        }
        private void handleClick2(object sender, EventArgs e)
        {
            durakGame.playGame(2);
        }
        private void handleClick3(object sender, EventArgs e)
        {
            durakGame.playGame(3);
        }
        private void handleClick4(object sender, EventArgs e)
        {
            durakGame.playGame(4);
        }
        private void handleClick5(object sender, EventArgs e)
        {
            durakGame.playGame(5);
        }

        private void handleClick6(object sender, EventArgs e)
        {
            durakGame.playGame(6);
        }

        private void initComputerCardBox()
        {
            /*computerCards = new List<CardBox>();
            computerCards.Add(cardBox1);
            computerCards.Add(cardBox2);
            computerCards.Add(cardBox3);
            computerCards.Add(cardBox4);
            computerCards.Add(cardBox5);
            computerCards.Add(cardBox6);*/


        }
        private void initMyCardBox() 
        {
           /* myCards = new List<CardBox>();
            myCards.Add(cardBox7);
            myCards.Add(cardBox8);
            myCards.Add(cardBox9);
            myCards.Add(cardBox10);
            myCards.Add(cardBox11);
            myCards.Add(cardBox12);
            foreach (CardBox cardbox in myCards)
            {
                cardbox.Cursor = Cursors.Hand;
            }
            cardBox12.cardBoxClicked += handleClick6;
            cardBox11.cardBoxClicked += handleClick5;
            cardBox10.cardBoxClicked += handleClick4;
            cardBox9.cardBoxClicked += handleClick3;
            cardBox8.cardBoxClicked += handleClick2;
            cardBox7.cardBoxClicked += handleClick1;*/

        }
        private void initTopCard()
        {
            topCard = cardBox13;
        }


        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void howToPlayToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GameRule rule = new GameRule();
            rule.ShowDialog();
        }

        private void cardBox13_Load(object sender, EventArgs e)
        {

        }

        private void cardBox12_Load(object sender, EventArgs e)
        {
           
        }

        private void cardBox12_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            durakGame.playGame(6);
        }

        private void cardBox12_Click(object sender, EventArgs e)
        {
           
        }

        private void mainPanel_Paint(object sender, PaintEventArgs e)
        {

        }

        public void setMessage(String msg)
        {
            message.Text = "";
        }

        public void setAttackVisible(Boolean visible) 
        {
            attack.Visible = visible;
        }

        public void setAcceptVisible(Boolean visible)
        {
            accept.Visible = visible;
        }

        private void startGameButton_Click(object sender, EventArgs e)
        {
            durakGame.startGame();
            startGameButton.Visible = false;
        }

        private void cardBox11_Load(object sender, EventArgs e)
        {

        }

        private void statistToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Statistics stat = new Statistics();
            stat.ShowDialog();
        }
    }
}
